package cn.com.oidreams.wechat.robot.entity;

import cn.com.oidreams.common.annotations.Required;
import cn.com.oidreams.wechat.robot.enums.WeXinTalkEnum;
import lombok.Data;

import java.util.Arrays;
import java.util.List;

/***
 ** @category 图文类型消息
 ** @author qing.yunhui
 ** @email: qingyh@glodon.com
 ** @createTime: 2021-12-14 20:26
 **/
@Data
public class NewsMsgRequest extends BaseRequest{

    @Required(errorMsg = "图文类型消息不能为空",classParse = true)
    private News news;

    public NewsMsgRequest(News news) {
        setMsgtype(WeXinTalkEnum.MSG_TYPE.NEWS.getCode());
        this.news = news;
    }

    /**
     * <p>图文类型消息</p>
     * */
    @Data
    public static class News {
        @Required(errorMsg = "图文消息不能不空",classParse = true)
        private List<Articles> articles;
        public News(List<Articles> articles) { this.articles = articles; }
        public News(Articles ...articles){
            this(Arrays.asList(articles));
        }
    }
    /**
     * <p>图文消息，一个图文消息支持1到8条图文</p>
     * */
    @Data
    public static class Articles {
        /**
         * <p>标题，不超过128个字节，超过会自动截断</p>
         * */
        @Required(errorMsg = "标题必填")
        private String title;
        /**
         * <p>点击后跳转的链接。</p>
         * */
        @Required(errorMsg = "url必填")
        private String url;
        /**
         * <p>描述，不超过512个字节，超过会自动截断</p>
         * */
        private String description;
        /**
         * <p>图文消息的图片链接，支持JPG、PNG格式，较好的效果为大图 1068*455，小图150*150。</p>
         * */
        private String picurl;
        public Articles(String title, String url){
            this(title,url,null,null);
        }
        public Articles(String title, String url, String description, String picurl) {
            this.title = title;
            this.url = url;
            this.description = description;
            this.picurl = picurl;
        }
    }

}
